﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication2
{
    public partial class Form3 : Form
    {
        private TextBox textbox = new TextBox();
        private string serch;

        public Form3()
        {
            InitializeComponent();

        }
        private void button1_Click(object sender,EventArgs e)
        {
             String ss = "server=localhost;User Id=root;Database=libmanager;Persist Security Info=True";
             MySqlConnection myconn = new MySqlConnection(ss);
             myconn.Open();
             String str = "select * from book where "+serch+" like '"+"%"+textbox.Text+"%"+"'";
             MySqlCommand mycmd = new MySqlCommand(str, myconn);
             MySqlDataReader myreader = mycmd.ExecuteReader();
             myreader.Read();
             try
             {
                object[] test = new object[10];
                myreader.GetValues(test);
                while (myreader.Read())
                {
                    myreader.GetValues(test);
                    
                }
                
                 textBox1.Text = myreader[1].ToString();
                 textBox2.Text = myreader[2].ToString();
                 textBox3.Text = myreader[5].ToString();
                 textBox4.Text = myreader[3].ToString();
            }
             catch(Exception err)
             {
                 MessageBox.Show("err", "cuowu", MessageBoxButtons.OK);
             }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 Form2 = new Form2();
            Form2.Show();
            this.Close();
        }


        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            
            
        }

        private void nameToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void 书名查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = false;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textbox = textBox1;
            serch = "BookName";
        }

        private void 出版社查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = false;
            textbox = textBox4;
            serch = "Publisher";
            
        }

        private void 作者查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
            textBox2.ReadOnly = false;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textbox = textBox2;
            serch = "Writer";
        }

        private void button3_Click(object sender, EventArgs e)
        {
           TempSt.myreader.Read();
        }

        private void Form3_Load(object sender, EventArgs e)
        {


        }
    }
}
